using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            string u = txtUsername.Text;
            string p = txtPassword.Text;
            
            logistics.Service lg = new logistics.Service();
            if (lg.lgUserCheckLogin(u, p) == true)
            {

                
                DataSet ds=lg.lgUserInfo(u);
                DataRow dr = ds.Tables["user"].Rows[0];
                //create session
                Session["username"] = u;
                Session["userid"] = dr["UserID"]; 
                Session["leveluser"] = dr["Level"];
                Session["branchid"] = dr["BranchID"];
                //end create session

                switch (dr["Level"].ToString()) { 
                    case "1":
                        Response.Redirect("admin/HO/Default.aspx");        
                        break;
                    case "2":
                        Response.Redirect("admin/EMP/Default.aspx");
                        break;
                    case "3":
                        Response.Redirect("user/Default.aspx");        
                        break;
                }
                
            }
            else {
                Response.Write("User name or password invalid!");
            }
        }
    }
}
